import 'package:flutter/material.dart';

import 'key_demo2.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: GlobalKeyDemo(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  final String title;
  MyHomePage({this.title}) {
    print('Widget构造方法来了!');
  }
  @override
  _MyHomePageState createState() {
    print('createState来了!');
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage> {
  _MyHomePageState() {
    print('State构造方法来了!');
  }
  @override
  void initState() {
    print('State的init来了!');

    super.initState();
  }

  int _count = 0;
  @override
  Widget build(BuildContext context) {
    print('State的Build来了!');
//    StatefulElement element = context;
    return Column(
      children: <Widget>[
        RaisedButton(
          child: Icon(Icons.add),
          onPressed: () {
//            element.markNeedsBuild();
            _count++;
            setState(() {});
          },
        ),
        Text('$_count'),
      ],
    );
  }

  @override
  void dispose() {
    print('State的dispose来了!');
    super.dispose();
  }

  @override
  void didChangeDependencies() {
    print('didChangeDependencies来了!');
    super.didChangeDependencies();
  }
}

/*
class MyHomePage extends StatelessWidget {
  final String title;
  MyHomePage({this.title}) {
    print('构造函数被调用了!');
  }

  @override
  Widget build(BuildContext context) {
    print('build方法被调用了!');
    return Center(
      child: Text(title),
    );
  }
}
 */
